package com.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.beans.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;


import com.beans.Admin;
import com.service.impl.AdminServiceImpl;

@Controller
@RequestMapping("/admin")
public class AdminController {
    @Resource
    AdminServiceImpl service;

    @RequestMapping("/get")
    public String get(String userName, ModelMap model) {
        System.out.println("get==>" + userName);
        if (userName != null && !userName.equals("")) {
            List<Admin> list = service.getone(userName);
            model.addAttribute("list", list);
            return "admin/alladmin";
        }
        model.addAttribute("error", "未查询到响应的数据，请您检查输入的数据名称是否正确~");
        return "admin/alladmin";
    }

    @RequestMapping("/getalladmin")
    public String getallAdmin(String userName, ModelMap m) {
        List<Admin> list = service.getone(userName);
        m.put("list", list);
        return "admin/alladmin";
    }

    @GetMapping("/updateadmin")
    public String updateAdmin(int id, ModelMap m) {
        Admin admin = service.getAdminById(id);
        m.put("admin", admin);
        return "admin/updateadmin";
    }
    
    /***************** 【以下为修改部分内容】 *********************/

    @RequestMapping("/queryByPage")
    @ResponseBody
    public Map<String, Object> queryByPage(Admin admin, Integer page, Integer limit) {
        return service.queryByPage(admin, page, limit);
    }

    @PostMapping("/gotoupdateadmin")
    @ResponseBody
    public Integer updateu(@RequestBody Admin admin) {
        return service.updateAdmin(admin);
    }

    @RequestMapping("/deleteadmin")
    @ResponseBody
    public Integer deleteu(int id) {
        return service.deleteAdmin(id);
    }

    @RequestMapping("/addadmin")
    @ResponseBody
    public Integer addAdmin(@RequestBody Admin admin) {
        return service.addAdmin(admin);
    }
}
